require 'rake/testtask'

task :default => :package

Rake::TestTask.new do |t|
  t.libs << "test"
  t.test_files = FileList['test/**/*_test.rb']
  t.verbose = true
end

desc 'remove all containers'
task :clear do
  FileUtils.cd(File.join(File.dirname(__FILE__), 'config')) do 
    FileUtils.cp '../system/haproxy.conf', 'haproxy.conf'
    Dir['sites/*/config/*'].each{|file| FileUtils.rm file}
    Dir['sites/*'].each{|entry| FileUtils.rm_rf entry}
    FileUtils.rm_f 'vhost.map'
  end
  system "rm -rf ddis/*"
end

desc 'package control center as zip file'
task :package => :clear do
  current_dir_name = File.basename(File.dirname(__FILE__))
  prj_name = "rails-control-center"
  version = "0.0.1"
  package_name = "#{prj_name}-#{version}"
  
  FileUtils.rm_f "#{package_name}.zip"
  
  FileUtils.cd ".." do
    FileUtils.mkdir_p "tmp/#{package_name}"
    system "cp -r #{current_dir_name}/* tmp/#{package_name}"
    FileUtils.cd "tmp" do
      system "find -name .svn|xargs rm -rf"
      FileUtils.cd package_name do
        system "rm -f *.zip"
        system "rm -rf config/sites/*"
        system "rm -rf ddis/*"
      end
      system "zip -r #{File.dirname(__FILE__)}/#{package_name}.zip #{package_name}"
    end
    FileUtils.rm_rf "tmp"
  end
end